home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Containers / SimpleApp / CSimpleAppSite.cpp < prev    next >
Encoding:
Text File  |  1996-12-20  |  4.3 KB  |  192 lines  |  [TEXT/CWIE]

  1. //
  2. //    CAppSite.cpp
  3. //
  4. //  Copyright (C) Microsoft Corporation, 1996
  5. //
  6.  
  7. #include "headers.h"
  8. #include "CSimpleAppSite.h"
  9. #include "CActiveXScheduler.h"
  10. #include "App.h"
  11.  
  12. //
  13. //  CSimpleAppSite::CBaseSite::AcquireContext
  14. //
  15.  
  16. STDMETHODIMP
  17. CSimpleAppSite::AcquireContext(Uint32 inContextID, DrawContext* outContext)
  18. {
  19.     AppData*     AppDataPtr = (AppData*) mContainerData;
  20.     ErrorCode    Result = S_OK;
  21.     Rect         ClipRect;
  22.     
  23.     //  Don't allow the object to nest calls to AcquireContext.  
  24.     if ( !mHavePort ) 
  25.     {
  26.         // Set up the context
  27.         switch (inContextID)
  28.         {
  29.             case WindowContextID:
  30.                 // Save off the current port state
  31.                 if (AppDataPtr->Window)
  32.                 {
  33.                     SavePortState((GrafPtr) AppDataPtr->Window);
  34.                     outContext->Port = AppDataPtr->Window;
  35.                     outContext->PortType = QDWindowPortType;
  36.                 }
  37.                 else
  38.                     Result =  E_FAIL;
  39.                 break;
  40. #ifdef USE_OFFSCREEN
  41.             case OffscreenContextID:
  42.                 if (AppDataPtr->Offscreen)
  43.                 {
  44.                     ::GetPort(&mSavePort);
  45.                     ::SetGWorld(AppDataPtr->Offscreen, NULL);
  46.                     mOldPortState.PortRect = AppDataPtr->Offscreen->portRect;
  47.                     mOldPortState.ClipRgn = NewRgn();
  48.                     ::GetClip(mOldPortState.ClipRgn);
  49.                     
  50.                     // Save off the pen state
  51.                     ::GetPenState(&mOldPortState.PenState);
  52.                     mOldPortState.TextFont = AppDataPtr->Offscreen->txFont;
  53.                     mOldPortState.TextMode = AppDataPtr->Offscreen->txMode;
  54.                     mOldPortState.TextSize = AppDataPtr->Offscreen->txSize;
  55.                     mOldPortState.TextFace = AppDataPtr->Offscreen->txFace;
  56.                     ::GetForeColor(&mOldPortState.ForeColor);
  57.                     ::GetBackColor(&mOldPortState.BackColor);
  58.                     outContext->Port = (GrafPtr) AppDataPtr->Offscreen;
  59.                     outContext->PortType = QDOffscreenPortType;
  60.                 }
  61.                 else
  62.                     Result =  E_FAIL;
  63.                 break;
  64. #endif // USE_OFFSCREEN
  65.             default:
  66.                 Result =  E_FAIL;
  67.                 break;
  68.         }
  69.     }
  70.     else
  71.         Result = E_FAIL;
  72.  
  73.     if (Result == S_OK)
  74.     {
  75.         outContext->ContextID = inContextID;        // okay, since we allow only one context above
  76.         outContext->ContainerRef = 0;                // we don't use this
  77.         outContext->DrawAspect = DVASPECT_CONTENT;
  78.     
  79.     // Location of the control
  80.     outContext->Location.left = 0;
  81.     outContext->Location.right = gControlRect.right - gControlRect.left;
  82.     outContext->Location.top = 0;
  83.     outContext->Location.bottom = gControlRect.bottom - gControlRect.top;
  84.  
  85.     ::SetRect(&ClipRect, 0, 0, outContext->Location.right, outContext->Location.bottom);
  86.     
  87.     // Initialize the port to a known state
  88.     ::SetOrigin(-(gControlRect.left), -(gControlRect.top));
  89.     ::ClipRect(&ClipRect);
  90.  
  91.     mHavePort = true;
  92.     }
  93.     else
  94.         outContext->Port = NULL;
  95.  
  96.     return Result;
  97. }
  98.  
  99.  
  100. //
  101. //  CSimpleAppSite::CBaseSite::OnChange
  102. //
  103. //  how controls tell us that they changed something
  104. //
  105.  
  106. STDMETHODIMP
  107. CSimpleAppSite::OnChange(ChangeType inChangeType)
  108. {
  109.     CXSite::OnChange(inChangeType);
  110. #ifdef USE_OFFSCREEN
  111.     if (inChangeType == ViewChange)
  112.     {
  113.         Rect        DestRect = { 0, 300, 290, 496};
  114.  
  115.         //    blit to the screen
  116.         ::ForeColor(blackColor);
  117.         ::BackColor(whiteColor);
  118.         CopyBits((BitMap*)(*(gAppData.Offscreen->portPixMap)),
  119.                 &((GrafPtr)gAppData.Window)->portBits, &gControlRect, &DestRect, srcCopy, NULL);
  120.     }
  121. #endif // USE_OFFSCREEN
  122.     return S_OK;
  123. }
  124.  
  125.  
  126. //
  127. //  CSimpleAppSite::CBaseSite::RequestSizeChange
  128. //
  129. //  how to change the controls size
  130. //
  131.  
  132. STDMETHODIMP
  133. CSimpleAppSite::RequestSizeChange ( Point* ioSize )
  134. {
  135.     ErrorCode    Result = S_OK;
  136.     GrafPtr        StartPort;
  137.     Point        BeginSize;
  138.     Point        MaxSize;
  139.  
  140.     BeginSize.h = gControlRect.right - gControlRect.left;
  141.     BeginSize.v = gControlRect.bottom - gControlRect.top;
  142.  
  143.     MaxSize.h = gAppData.Window->portRect.right - gControlRect.left - 10;
  144.     MaxSize.v = gAppData.Window->portRect.bottom - gControlRect.top - 10;
  145.  
  146.     if (ioSize->v > MaxSize.v)
  147.     {
  148.         ioSize->v = MaxSize.v;
  149.         Result = S_FALSE;
  150.     }
  151.  
  152.     if (ioSize->h > MaxSize.h)
  153.     {
  154.         ioSize->h = MaxSize.h;
  155.         Result = S_FALSE;
  156.     }
  157.  
  158.     gControlRect.bottom = gControlRect.top + ioSize->v;
  159.     gControlRect.right = gControlRect.left + ioSize->h;
  160.  
  161.     ::GetPort(&StartPort);
  162.     ::SetPort(gAppData.Window);
  163.     ::InvalRect(&gAppData.Window->portRect);
  164.     ::SetPort(StartPort);
  165.  
  166.     return Result;
  167. }
  168.  
  169.  
  170. //
  171. //  CSimpleAppSite::GetContextID
  172. //
  173.  
  174. Boolean8
  175. CSimpleAppSite::GetContextID(Int32 inContextIndex, UInt32* outContextID)
  176. {
  177.     // Since we only support 1 context, and we use the index (1)
  178.     // to map to that context, we can just use the AcquireContextByIndex method
  179.     if ( inContextIndex <= 1 )
  180.     {
  181.         *outContextID = 1;
  182.         return true;
  183.     }
  184.     else
  185.     {
  186.         *outContextID = InvalidContextID;
  187.         return false;
  188.     }
  189. }
  190.  
  191.  
  192.